home *** CD-ROM | disk | FTP | other *** search
- /*
- XList.hh
-
- Copyright 1996-1997 Joshua Juran
- */
-
- /*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- #pragma once
-
- #include <Types.h>
-
- #include "XObject.hh"
-
- class CXNode {
- friend class XList;
- public:
- CXNode(XObject *inNewDatum) : mNext(NULL), mDatum(inNewDatum->retain()) {}
- ~CXNode() {mDatum->release();}
- void AddNext(XObject *inNewDatum);
- CXNode *RemoveNext();
- CXNode *Next() const {return mNext;}
- XObject *Datum() const {return mDatum;}
- protected:
- CXNode *mNext;
- XObject * mDatum;
- };
-
-
- class XList {
- // For debugging
- private:
- unsigned long mNote;
- public:
- XList() : mNote('list'), mHead(NULL) {}
- ~XList();
-
- protected:
- CXNode *HeadNode() const {return mHead;}
- // No, that's not a typo. No need to zero both of them.
- CXNode *TailNode() const {return mHead ? mTail : NULL;}
- CXNode *FindNode(XObject * inDatum) const;
-
- public:
- XObject *FirstDatum() const {return HeadNode() ? HeadNode()->Datum() : NULL;}
- XObject *LastDatum() const {return TailNode() ? TailNode()->Datum() : NULL;}
- XObject *Successor(XObject * inDatum) const {
- return (FindNode(inDatum) && FindNode(inDatum)->Next())
- ? FindNode(inDatum)->Next()->Datum()
- : (XObject *)NULL;
- }
-
- void Prepend(XObject *inNewDatum);
- void Append(XObject *inNewDatum);
- XObject *Behead();
- void Remove(XObject *inVictim);
- void Purge();
- protected:
- CXNode *mHead;
- CXNode *mTail;
- };
-